import supe from './super.js';

export default class extends supe {

  render() {
    this.node.html(`
    <div style="margin:100px auto;width:500px;">
        <form class="layui-form">
  <div class="layui-form-item">
    <label class="layui-form-label">账号</label>
    <div class="layui-input-inline">
      <input type="text" name="user" required  lay-verify="required" placeholder="请输入账号" autocomplete="off" class="layui-input" id="user">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">密码</label>
    <div class="layui-input-inline">
      <input type="password" name="pwd" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input" id="pwd">
    </div>
    <div class="layui-form-mid layui-word-aux"></div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button type="button" class="layui-btn" lay-submit lay-filter="formDemo" id="loginBtn">登录</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
</div>
        `)
  }

  handle() {
    $('#loginBtn').on('click', function () {
      if ($('#user').val() != '' && $('#pwd').val() != '') {
        $.ajax({
          type: 'get',
          url: '/login/login/' + $('#user').val() + '/' + $('#pwd').val(),
          dataType: 'json',
          success: (data) => {
            data ? location.href = '#/main' : alert(`登录失败`);
          }
        })
      }
    })
  }
}

